// 智能组牌
#include <bits/stdc++.h>
#include <queue>
#include <vector>
using namespace std;
int Ha[100];

// 分割字符串
vector<string> split(string s) {
  vector<string> v;
  int pos1 = 0;
  while (1) {
    int pos2 = s.find(" ", pos1);
    if (std::string::npos == pos2)
      break;
    v.push_back(s.substr(pos1, pos2 - pos1));
    pos1 = pos2 + 1;
  }
  if (pos1 != s.length())
    v.push_back(s.substr(pos1));
  return v;
}

// 连成顺子，还是三个，还是双的， 使得<2de 的牌尽量少
int work(string pork) {
  memset(Ha, 0, sizeof(Ha));
  vector<string> v = split(pork);
  for (int i = 1; i < v.size(); i += 2) {
    int k = stoi(v[i], 0);
    cout << k << endl;
    (Ha[k]+=1)%=6;  //消平哪些多余多余的牌。三连对， 双对 都可以
  }
  

  
  int ans = 0;

  return ans;
}
int main() {
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string pork;
    getline(cin, pork);
    cout << work(pork) << endl;
  }

  return 0;
}
